Skip to content

Add expand() to read tagged-pointer size types back as enums - #1129

Merged
nicoburns merged 1 commit into
DioxusLabs:mainfrom
ChrisJr404:expand-tagged-pointer-sizes
Aug 21, 2026
Merged

Add expand() to read tagged-pointer size types back as enums#1129
nicoburns merged 1 commit into
DioxusLabs:mainfrom
ChrisJr404:expand-tagged-pointer-sizes

Conversation

@ChrisJr404

Copy link
Copy Markdown
Contributor

Closes #824.

The size style types (LengthPercentage, Dimension, and the grid track sizing functions) became tagged pointers over CompactLength a while back, which is great for size but means there's no longer an easy way to read the original value back out. As the issue points out, integrations like egui_taffy need to inspect a Style and branch on what each property actually is, and today the only way to do that is to go through into_raw() and match on the raw tag yourself.

This adds an expand() method to each of LengthPercentage, LengthPercentageAuto, Dimension, MinTrackSizingFunction and MaxTrackSizingFunction that returns a matching Expanded* enum (ExpandedLengthPercentage, ExpandedDimension, and so on). The variants line up one-to-one with each type's public constructors, and there are From impls in both directions so a value round-trips, e.g. Dimension::from(dim.expand()) == dim. calc() is represented as an opaque *const () variant behind the calc feature, matching the existing calc/into_raw surface, so nothing extra is exposed when that feature is off.

I went with the ExpandedLengthPercentage shape you sketched in the issue. I held off on the separate lightweight LengthPercentageTag discriminant enums for now, mainly because a natural tag() accessor would collide with the existing Dimension::tag() -> usize and I wasn't sure what you'd want to call it. Happy to add those in this PR if you'd like them, just let me know the naming you'd prefer.

Round-trip tests for every variant (including calc) live next to each type, and there's a CHANGELOG entry under Added. cargo fmt, cargo clippy --all-targets and the lib tests are all clean.

Since the size style types became tagged pointers rather than enums it is
awkward to recover the original value of a property, which integrations such
as egui_taffy need in order to inspect a style. Give LengthPercentage,
LengthPercentageAuto, Dimension, MinTrackSizingFunction and
MaxTrackSizingFunction an expand() method returning a matching Expanded*
enum, with From conversions in both directions so the value round-trips.
@nicoburns
nicoburns force-pushed the expand-tagged-pointer-sizes branch from 30c126d to e5e96dc Compare August 21, 2026 15:02
@nicoburns
nicoburns merged commit 8a11081 into DioxusLabs:main Aug 21, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Taffy 0.8 - Allow retrieving underlying size from tagged pointer.

2 participants